import csv

class Question:
    def __init__(self, question_id, content, options, answer):
        self.question_id = question_id
        self.content = content
        self.options = options
        self.answer = answer


def generate_exam_paper(questions, filename="exam_paper.csv"):
    """
    生成试卷CSV文件
    :param questions: 试题列表，每个元素为Question对象
    :param filename: 输出的CSV文件名，默认为exam_paper.csv
    """
    with open(filename, 'w', newline='', encoding='utf-8') as csvfile:
        fieldnames = ['Question ID', 'Content', 'Option A', 'Option B', 'Option C', 'Option D', 'Answer']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

        writer.writeheader()
        for q in questions:
            # 假设每个问题有四个选项，根据实际情况调整
            row = {
                'Question ID': q.question_id,
                'Content': q.content,
                'Option A': q.options[0],
                'Option B': q.options[1],
                'Option C': q.options[2],
                'Option D': q.options[3],
                'Answer': q.answer
            }
            writer.writerow(row)

def print_exam_paper(questions):
    """
    在控制台打印试卷内容
    :param questions: 试题列表，每个元素为Question对象
    """
    for q in questions:
        print(f"Question ID: {q.question_id}")
        print(f"Content: {q.content}")
        for i, option in enumerate(q.options, start=65):  # 65对应ASCII码中的'A'
            print(f"Option {chr(i)}: {option}")
        print(f"Answer: {q.answer}\n")

# 使用之前的试题示例进行打印
questions = [
    Question(1, "地球的形状是什么？", ["A.正方形", "B.圆形", "C.三角形", "D.椭圆形"], "D"),
    Question(2, "太阳系中最大的行星是？", ["A.地球", "B.木星", "C.火星", "D.金星"], "B")
]

print_exam_paper(questions)